﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace housingsafety.server.Svcs
{
    public interface IRedisUtils
    {
        ConnectionMultiplexer Instance { get; }

        long AddList<T>(int dbIndex, string listId, List<T> list);
        string ConvertJson<T>(T value);
        T ConvertObj<T>(RedisValue value);
        List<T> ConvetList<T>(RedisValue[] values);
        List<T> GetList<T>(int dbIndex, string listId, long start = 0, long stop = -1);
        bool HashDelete(int dbIndex, string hashId, string key);
        bool HashExists(int dbIndex, string hashId, string key);
        string HashGet(int dbIndex, string hashId, string key);
        T HashGet<T>(int dbIndex, string hashId, string key);
        List<T> HashGetAll<T>(int dbIndex, string hashId);
        List<string> HashKeys(int dbIndex, string hashId);
        long HashLength(int dbIndex, string hashId);
        bool HashSet<T>(int dbIndex, string hashId, string key, T t);
        bool KeyDelete(int dbIndex, string key);
        Task<bool> KeyDeleteAsync(int dbIndex, string key);
        bool KeyExists(int dbIndex, string key);
        bool KeyRename(int dbIndex, string oldKey, string newKey);
        Task<bool> KeyRenameAsync(int dbIndex, string oldKey, string newKey);
        long ListLength(int dbIndex, string listId);
        long Publish(string channel, string message);
        bool SetAdd<T>(int dbIndex, string key, T value);
        Task<bool> SetAddAsync<T>(int dbIndex, string key, T value);
        string[] SetCombine(int dbIndex, SetOperation operation, string firstKey, string secondKey);
        Task<string[]> SetCombineAsync(int dbIndex, SetOperation operation, string firstKey, string secondKey);
        bool SetContains<T>(int dbIndex, string key, T value);
        Task<bool> SetContainsAsync<T>(int dbIndex, string key, T value);
        bool SetExpire(int dbIndex, string key, int timeout = 0);
        bool SetExpire(int dbIndex, string key, TimeSpan? expiry);
        long SetLength(int dbIndex, string key);
        Task<long> SetLengthAsync(int dbIndex, string key);
        List<T> SetMembers<T>(int dbIndex, string key);
        Task<List<T>> SetMembersAsync<T>(int dbIndex, string key);
        bool SetMove<T>(int dbIndex, string sourceKey, string destinationKey, T value);
        Task<bool> SetMoveAsync<T>(int dbIndex, string sourceKey, string destinationKey, T value);
        T SetPop<T>(int dbIndex, string key);
        Task<T> SetPopAsync<T>(int dbIndex, string key);
        string[] SetRandomMember(int dbIndex, string key, long count);
        T SetRandomMember<T>(int dbIndex, string key);
        Task<T> SetRandomMemberAsync<T>(int dbIndex, string key);
        Task<string[]> SetRandomMembersAsync(int dbIndex, string key, long count);
        bool SetRemove(int dbIndex, string key, string value);
        Task<bool> SetRemoveAsync(int dbIndex, string key, string value);
        IEnumerable<RedisValue> SetScan(int dbIndex, string key);
        long SortedSetAdd<T>(int dbIndex, string key, List<T> value, double? score = null);
        bool SortedSetAdd<T>(int dbIndex, string key, T value, double? score = null);
        Task<long> SortedSetAddAsync<T>(int dbIndex, string key, List<T> value, double? score = null);
        Task<bool> SortedSetAddAsync<T>(int dbIndex, string key, T value, double? score = null);
        long SortedSetLength(int dbIndex, string key);
        Task<long> SortedSetLengthAsync(int dbIndex, string key);
        long SortedSetLengthByValue<T>(int dbIndex, string key, T startValue, T endValue);
        Task<long> SortedSetLengthByValueAsync<T>(int dbIndex, string key, T startValue, T endValue);
        double SortedSetMaxScore(int dbIndex, string key);
        Task<double> SortedSetMaxScoreAsync(int dbIndex, string key);
        double SortedSetMinScore(int dbIndex, string key);
        List<T> SortedSetRangeByRank<T>(int dbIndex, string key, long start = 0, long stop = -1, bool desc = false);
        long SortedSetRemove<T>(int dbIndex, string key, params T[] value);
        Task<long> SortedSetRemoveAsync<T>(int dbIndex, string key, params T[] value);
        long SortedSetRemoveRangeByRank(int dbIndex, string key, long start, long stop);
        Task<long> SortedSetRemoveRangeByRankAsync(int dbIndex, string key, long start, long stop);
        long SortedSetRemoveRangeByScore(int dbIndex, string key, double start, double stop);
        long SortedSetRemoveRangeByValue<T>(int dbIndex, string key, T startValue, T endValue);
        Task<long> SortedSetRemoveRangeByValueAsync<T>(int dbIndex, string key, T startValue, T endValue);
        double? SortedSetScore<T>(int dbIndex, string key, T value);
        string StringGet(int dbIndex, string key);
        T StringGet<T>(int dbIndex, string key) where T : class;
        Task<T> StringGetAsync<T>(int dbIndex, string key) where T : class;
        bool StringSet(int dbIndex, string key, RedisValue value, TimeSpan? expiry);
        bool StringSet<T>(int dbIndex, string key, T value, TimeSpan? expiry) where T : class;
        Task<bool> StringSetAsync<T>(int dbIndex, string key, T value, TimeSpan? expiry) where T : class;
        void Subscribe(string channelFrom);
    }
}